home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2001 May / SGI IRIX 6.5 Applications 2001 May.iso / dev / insight_dev.idb / usr / lib / Insight / dweb / dtl2html / sgibook.dwc.z / sgibook.dwc
Encoding:
Text File  |  2001-04-05  |  14.3 KB  |  433 lines

  1.  
  2. #####################################################################
  3. #####################################################################
  4. ##                                                                 ##
  5. ##             BOOK TEXT VIEW CREATION                             ##
  6. ##                                                                 ##
  7. #####################################################################
  8. #####################################################################
  9.  
  10. dwScript Plain__BookTextView {
  11.     dwProcessTemplate Plain__BookTextViewTmpl
  12. }
  13.  
  14. dwTemplate Plain__BookTextViewTmpl {
  15. $[dwCall dwMakeUrlParts]
  16. <HTML>
  17.   <HEAD>
  18.     <TITLE>$[dwGetRootTitle]</TITLE>
  19.   </HEAD>
  20. <BODY>
  21. <!-- SGISTART:$[dwGetRootTitle] -->
  22.     $[dwInitPageTextGenerator [dwGet TextStylesheet] [dwGet DoReveal]]
  23.     $[dwCall Generic__GeneratePageText]
  24. <!-- SGIEND:$[dwGetRootTitle] -->
  25. </BODY>
  26. </HTML>
  27. }
  28.  
  29.  
  30. dwScript Generic__GeneratePageText {
  31.    set keep_going 1
  32.    set text_size 0
  33.  
  34.    ## initialize to empty string since there is currently no link
  35.    dwSet ahref ""
  36.  
  37.    dwFlushPipe
  38.  
  39.    while {$keep_going} {
  40.       set text [dwGetPageText]
  41.       dwSend $text
  42.       set text_size [expr $text_size + [string length $text]]
  43.       
  44.       set interrupt [dwGetPageInterrupt]
  45.       switch -exact $interrupt {
  46.          end_of_page         {set keep_going 0}
  47.          exceeded_page_size  {set keep_going 1}
  48.          start_script        {dwCall Generic__HandleStartScript}
  49.          end_script          {dwCall Generic__HandleEndScript}
  50.          inline_figure       {dwCall Generic__HandleInlineFigure}
  51.          inline_icon         {dwCall Generic__HandleInlineIcon}
  52.          default             {}
  53.       }
  54.    }
  55. }
  56.  
  57.  
  58. dwScript Plain__BookTocTextView {
  59.  
  60.     dwInitTocLineGenerator 5 [dwGet State__TocStyle]
  61.     dwSet HilitePosition 0
  62.     dwSet TocTitleBefore ""
  63.     dwSet TocTitleAfter ""
  64.     dwSet TopScrollPoint ""
  65.     dwSet ScrollPosition ""
  66.     dwSet ShowingTocView 1
  67.  
  68.     set skip_item 0
  69.     set title [dwGetRootTitle]
  70.     regsub -all {\<[\/-z]+\>}  $title {} title
  71.  
  72.     dwSetContentType "text/plain"
  73.  
  74.     if {[dwGetTocNumEntries] > 1} {
  75.  
  76.       dwSend "0|$title|0\n";
  77.       while {[dwNewTocLine]} {
  78.  
  79.         set title [dwGetTocItemTitle]
  80.         regsub -all {\<[\/-z]+\>} $title {} title
  81.  
  82.         if {[dwGetTocItemLevel] == 1 && ([dwGetTocItemTitle] == "Glossary" || [dwGetTocItemTitle] == "Index")} {
  83.             dwSend "[dwGetTocItemLevel]|[string trimleft $title {" "}]|[dwGetTocItemPath]\n";
  84.             set skip_item 1
  85.         }
  86.  
  87.         if {$title != "" && $skip_item == 0} {
  88.             dwSend "[dwGetTocItemLevel]|[string trimleft $title {" "}]|[dwGetTocItemPath]\n";
  89.         }
  90.       }
  91.     }
  92. }
  93.  
  94.  
  95. #####################################################################
  96. ##                                                                 ##
  97. ##                SCRIPT HANDLERS                                  ##
  98. ##                                                                 ##
  99. #####################################################################
  100.  
  101. dwScript Generic__HandleInlineIcon {
  102.   dwCall Generic__ProcessScriptInfo
  103.  
  104.   set icon_name [dwGet Script_name]
  105.   set icon_file images/[string tolower ${icon_name}.gif]
  106.  
  107.   dwSet Inline_imgSrc $icon_file
  108.   dwSet Inline_imgAlt $icon_name
  109.   dwSet Inline_imgBorder 0
  110.   dwSet Inline_imgAlign absmiddle
  111.   dwCall Generic__InlineHandler
  112. }
  113.  
  114. dwScript Generic__HandleInlineFigure {
  115.  
  116.   dwCall Generic__ProcessScriptInfo
  117.  
  118.   if {[dwGet Script_name] == "custom"} {
  119.      dwCall Generic__HandleStartScript
  120.   } else {
  121.      dwSet Inline_imgSrc    images/[dwGet Script_fname]
  122.      dwSet Inline_imgAlt    [dwGet Script_fname]
  123.      dwSet Inline_imgBorder 0
  124.      dwSet Inline_imgAlign  absmiddle
  125.      dwCall Generic__InlineHandler
  126.   }
  127. }
  128.  
  129. dwScript Generic__InlineHandler {
  130.   if {[dwGet Inline_imgAlt] == "sgilink"} {
  131.       ;
  132.   } else {
  133.       dwProcessTemplate Generic__InlineHtml
  134.   }
  135. }
  136.  
  137. dwTemplate Generic__InlineHtml {
  138.     <IMG SRC="$[dwGet Inline_imgSrc]" ALT="$[dwGet Inline_imgAlt]" BORDER="$[dwGet Inline_imgBorder]" ALIGN="$[dwGet Inline_imgAlign]">
  139. }
  140.  
  141.  
  142. ##=========================================================================##
  143. ##   These scripts handle EBT stylesheet <script>s.
  144. ##=========================================================================##
  145.  
  146. dwScript Generic__HandleStartScript {
  147.  
  148.    dwCall dwMakeUrlParts
  149.    dwCall Generic__ProcessScriptInfo
  150.  
  151.    set script [dwGet Script_name]
  152.    set params [dwGet Script_params]
  153.  
  154.    switch -exact $script {
  155.     sgi-glossary       {}
  156.     ebt-launch         {dwCall SetUpEbtLaunch}
  157.     default            {
  158.       if {[dwGet Script_params] == ""} {
  159.         dwSend "<A HREF=\"@$script\">"
  160.       } else {
  161.         dwSend "<A HREF=\"@$script?$params\">"
  162.       }
  163.     }
  164.    }
  165. }
  166.  
  167. dwScript Generic__HandleEndScript {
  168.  
  169.   dwCall Generic__ProcessScriptInfo
  170.  
  171.   switch -exact [dwGet Script_name] {
  172.     sgi-glossary  {}
  173.     default       {dwSend "</A>"}
  174.   }
  175. }
  176.  
  177. ##=========================================================================##
  178. ## Get the interrupt info for the script, and massage it into a form
  179. ## suitable for stashing it as the "query params" of a URL.
  180. ## TODO: a [dwUrlEncode string] command of some sort.
  181. ##=========================================================================##
  182.  
  183. dwScript Generic__ProcessScriptInfo {
  184.  
  185.    ## Get the script information (script-name param1=valu1 param2=value2 ...)
  186.    ## Break apart the parameter/value sets (param=value ==> param = value)
  187.    ## because TCL gets confused by embedded quotes (param="value with spaces")
  188.  
  189.    set info [dwGetPageInterruptInfo]
  190.    regsub -all {= } $info {="" } info
  191.    regsub -all {=} $info { = } info
  192.  
  193.    ## Script name is easy!
  194.    dwSet Script_name [lindex $info 0]
  195.  
  196.    ## Initialize some stuff.
  197.    dwSet Script_params ""
  198.    dwSet Script_book ""
  199.    dwSet Script_collection ""
  200.    dwSet Script_window ""
  201.    dwSet Script_target ""
  202.    dwSet Script_currentPath ""
  203.    dwSet Script_fname  ""
  204.  
  205.    dwSet Script_containsHit 0
  206.    set gotBook 0
  207.    set gotCollection 0
  208.    set gotWindow 0
  209.    set gotTarget 0
  210.    set gotMe 0
  211.    set gotHit 0
  212.    set gotTname  0
  213.    set gotTvalue 0
  214.    set gotFname  0
  215.  
  216.    ## Now glue the list back together, separating param/value pairs by ";"s.
  217.    ## Also url-encode them. 
  218.    set nitems [llength $info]
  219.    if {$nitems > 1} {
  220.       set next_sep {;}
  221.       for {set i 1} {$i < $nitems} {incr i} {
  222.          set sep $next_sep
  223.          set next_sep {;}
  224.          set item [lindex $info $i]
  225.  
  226.          ## No semicolons around the "="!
  227.          ## Also, as aspecial favor to ebt-link, we keep track of
  228.          ## book= and collection= params.
  229.          if {$item == "="} {
  230.             set sep ""
  231.             set next_sep ""
  232.          } else {
  233.            if {$sep == ";"} {
  234.               set gotBook 0
  235.               set gotCollection 0
  236.               set gotWindow 0
  237.               set gotTarget 0
  238.               set gotTname  0
  239.               set gotTvalue 0
  240.               set gotFname  0
  241.               set gotMe 0
  242.           set getHit 0
  243.               if {[string tolower $item] == "book"} {
  244.                  set gotBook 1
  245.               } elseif {[string tolower $item] == "collection"} {
  246.                  set gotCollection 1
  247.               } elseif {[string tolower $item] == "window"} {
  248.                  set gotWindow 1
  249.               } elseif {[string tolower $item] == "target"} {
  250.                  set gotTarget 1
  251.               } elseif {[string tolower $item] == "__me__"} {
  252.                  set gotMe 1
  253.               } elseif {[string tolower $item] == "__hit__"} {
  254.                  set gotHit 1
  255.               } elseif {[string tolower $item] == "tvalue"} {
  256.                  set gotTvalue 1
  257.               } elseif {[string tolower $item] == "tname"} {
  258.                  set gotTname 1
  259.               } elseif {[string tolower $item] == "filename"} {
  260.                  set gotFname 1
  261.               } elseif {[string tolower $item] == "parm1"} {
  262.                  set gotFname 1
  263.               }
  264.  
  265.            } elseif {$gotBook} {
  266.               set Script_book $item
  267.            } elseif {$gotCollection} {
  268.               set Script_collection $item
  269.            } elseif {$gotWindow} {
  270.               set Script_window [string tolower $item]
  271.            } elseif {$gotTarget} {
  272.               set Script_target $item
  273.            } elseif {$gotMe} {
  274.               set Script_currentPath $item
  275.            } elseif {$gotHit} {
  276.               set Script_containsHit $item
  277.            } elseif {$gotTvalue} {
  278.               set Script_target IDMATCH(id,$item)
  279.               set newitem target=$Script_target
  280.               set item $newitem
  281.               set sep  {;}
  282.               set gotTvalue 0
  283.            } elseif {$gotFname} {
  284.               set Script_fname $item
  285.            }
  286.          }
  287.  
  288.          if {[llength $item] > 1} {
  289.             set item \"$item\"
  290.             regsub -all { = } $item {=} item
  291.          }
  292.  
  293.          if {$gotTvalue} {
  294.          } elseif {$gotTname} {
  295.          } else {
  296.               dwSet Script_params "$Script_params$sep[dwUrlEncode $item]"
  297.          }
  298.       }
  299.    }
  300.  
  301.    ## Don't propagate internally generated state info.
  302.    regsub -all {__[^_]*__=[^;]*} $Script_params {} Script_params
  303.  
  304.    ## Clean up extraneous ;'s
  305.    regsub -all {;;} $Script_params {;} Script_params
  306.    set Script_params [string trim $Script_params ";"]
  307.  
  308.    ## Don't blindly pass up a null script name
  309.    if {$Script_name == ""} {dwSet Script_name "script_error"}
  310.  
  311.    ## Don't return anything
  312.    dwReturn
  313. }
  314.  
  315.  
  316. dwScript SetUpEbtLaunch {
  317.  
  318.    set info [dwGetPageInterruptInfo]
  319.    set nrcheck "bin/nr"
  320.    set len [string last $nrcheck $info]
  321.  
  322.    if {$len > 0} {
  323.        set full_len [expr $len+[string length $nrcheck]]
  324.        set tmp  [string range $info $full_len end]
  325.        set ftmp [string trimright $tmp {";,}]
  326.        set tmp  [string trimleft  $ftmp {" "}]
  327.        dwSend "<A HREF=\"$tmp\" TARGET=\"_blank\">"
  328.    } else {
  329.        dwSend "<A NAME=\"sgi_no_link\">"
  330.    }
  331. }
  332.  
  333.  
  334. ##===========================================================================
  335. ##   URL construction utilities.
  336. ##===========================================================================
  337.  
  338. #############################################################################
  339. ##                                                                         ##
  340. ##  Mostly by convention, the DynaWeb URL looks something like:            ##
  341. ##                                                                         ##
  342. ##     http://www.ebt.com/<service>/<path>;<url_params>?<query_params>     ##
  343. ##                                                                         ##
  344. ##  where <service> is usually "dynaweb" and where <path> consists of:     ##
  345. ##                                                                         ##
  346. ##     <root_path>/@<script_name>/<selection>                              ##
  347. ##                                                                         ##
  348. ##  and where <root_path> consists of:                                     ##
  349. ##                                                                         ##
  350. ##     <collection_name>/<collection_name>/.../<book_name>                 ##
  351. ##                                                                         ##
  352. ##  Note that <script> may refer to either a dwScript or a dwTemplate,     ##
  353. ##  and <selection> semantics are script-dependent.                        ##
  354. ##                                                                         ##
  355. ##  Example:                                                               ##
  356. ##                                                                         ##
  357. ##  http://www.ebt.com/dynaweb/Manuals/Admin_guide/@BookTocView/446        ##
  358. ##                       |        |           |           |       |        ##
  359. ##         Service-------+        |           |           |       |        ##
  360. ##                   Collection---+           |           |       |        ##
  361. ##                                Book--------+           |       |        ##
  362. ##                                      Viewing template--+       |        ##
  363. ##                                                   Target node--+        ##
  364. ##                                                                         ##
  365. #############################################################################
  366. #############################################################################
  367.  
  368. ##==============================================================================
  369. ## Build URL fragments that are suitable for constructing 
  370. ## different kinds of URLs.  The following parts are made:
  371. ##
  372. ##   BaseUrl - A fully qualified URL including the root path
  373. ##             (note: ends with a '/').  Suitable for use as a <BASE> HREF.
  374. ##             Example: http://www.foo.com/dynaweb/collection/book/
  375. ##
  376. ##   BasePath - Like the BaseUrl, but does not include the
  377. ##             scheme, host, or port, and does not end with '/'.
  378. ##             Suitable for use as a relative Url.
  379. ##             Example: /dynaweb/collection/book
  380. ##
  381. ##   RootAbsUrlPath - Like BasePath, but does not include the
  382. ##             URL prefix or service.
  383. ##             Example: /collection/book
  384. ##
  385. ##   UrlQueryString - If a query is active this will be a string
  386. ##             representing the query preceded by a '?' that is
  387. ##             suitable for tacking on the end of URLs
  388. ##             Example: ?DwebQuery=this+is+a+search+string
  389. ##
  390. ##   UrlParamString - This is a string that is suitable for
  391. ##             inserting in the URL between the path and the
  392. ##             query string. It contains state variables for
  393. ##             the current "session".
  394. ##             Example: ;td=3;hf=1
  395. ##
  396. ##   Careful: If RootPath is empty, avoid sending back a trailing slash.
  397. ##=============================================================================
  398.  
  399. dwScript dwMakeUrlParts {
  400.     set root      [dwGetRootPath]
  401.     set service   [dwGetUrlNthPathSeg 0]
  402.     set prefix    [dwGetUrlPrefix]
  403.     set script    [dwGetUrlNthPathSeg [expr [dwGetUrlNumPathSegs] - 1]]
  404.  
  405.     if {$prefix == "/"} {set prefix ""}
  406.     
  407.     ## Build BasePath, RootAbsUrlPath, and BaseUrl
  408.     
  409.     dwSet BasePath $prefix/$service
  410.     dwSet Service $service
  411.     
  412.     if {$root == ""} {
  413.         dwSet RootAbsUrlPath $prefix/$service
  414.     } else {
  415.         dwSet RootAbsUrlPath $prefix/$service/$root
  416.     }
  417.     
  418.     set port [dwGetUrlPort]
  419.     if {$port == "80"} {
  420.          dwSet dwPort :$port
  421.     } else {
  422.          set dwPort ""
  423.     }
  424.  
  425.     dwSet UrlQueryString ""
  426.     dwSet UrlParamString ""
  427.     dwSet BaseUrl \
  428.           "[dwGetUrlScheme]://[dwGetUrlServer]:[dwGetUrlPort]$RootAbsUrlPath/"
  429.  
  430.     dwReturn
  431. }
  432.  
  433.